#include "BleKeyboard.h"
#include <Arduino.h>
#include <string.h>

void BleKeyboard::begin(NimBLEHIDDevice* hid) {
  inputKeyboard = hid->getInputReport(2);  // Report ID 2：键盘
}

void BleKeyboard::sendKey(uint8_t keycode) {
  uint8_t report[] = {0x00, 0x00, keycode, 0, 0, 0, 0, 0};
  inputKeyboard->setValue(report, sizeof(report));
  inputKeyboard->notify();
  delay(50);

  memset(report, 0, sizeof(report));
  inputKeyboard->setValue(report, sizeof(report));
  inputKeyboard->notify();
}

void BleKeyboard::sendCombination(uint8_t modifier, uint8_t keycode) {
  uint8_t report[] = {modifier, 0x00, keycode, 0, 0, 0, 0, 0};
  inputKeyboard->setValue(report, sizeof(report));
  inputKeyboard->notify();
  delay(50);

  memset(report, 0, sizeof(report));
  inputKeyboard->setValue(report, sizeof(report));
  inputKeyboard->notify();
}
